import {
  mapGetters,
  mapState
} from 'vuex'
import cart from '../store/cart'
export default {
  computed: {
    ...mapGetters('m_cart', ['total']),
    ...mapState('m_cart',['cart'])
  },
  onShow() {
    this.setBadge()
  },
  methods: {
    setBadge() {
      uni.setTabBarBadge({
        index: 2,
        text: this.total + '' //徽标内容只能是字符串不能是数字
      })
      if (this.total === 0){
        uni.removeTabBarBadge({
          index:2
        })
      }
    }
  },
  watch:{
    total(){
      this.setBadge()
    }
  }
}
